define(function(require, exports, module) {
	var doc = document;
	var $ = mui;
	// 引入依赖
	var app = require('../../core/app');
	var userInfo = require('../../core/userInfo');
	var mbank = require('../../core/bank');
	var nativeUI = require('../../core/nativeUI');
	var format = require('../../core/format');
	var userAcc = require('../../core/userAcc');

	$.init();

	$.plusReady(function() {
		var myShare2 = doc.getElementById("myShare2");
		var shares = null;
		var Intent = null,
			File = null,
			Uri = null,
			main = null;
		// H5 plus事件处理
		if(plus.os.name == "Android") {
			Intent = plus.android.importClass("android.content.Intent");
			File = plus.android.importClass("java.io.File");
			Uri = plus.android.importClass("android.net.Uri");
			main = plus.android.runtimeMainActivity();
		}
		getSerivces();

		function getSerivces() {
			plus.share.getServices(function(shareDate) {
				shares = {};
				for(var i in shareDate) {
					var s = shareDate[i];
					shares[s.id] = s;
				}
			}, function(e) {
				alert("获取分享服务列表失败：" + e.message);
			});
		}
		myShare2.addEventListener("click", function() {
			shareHref();
		})

		function shareHref() {
			var shareBts = [];
			var s_weixin = shares['weixin'];
			s_weixin && s_weixin.nativeClient && (shareBts.push({
					title: '微信朋友圈',
					s: s_weixin,
					x: 'WXSceneTimeline'
				}),
				shareBts.push({
					title: '微信好友',
					s: s_weixin,
					x: 'WXSceneSession'
				}));
			// 弹出分享列表
			shareBts.length > 0 ? plus.nativeUI.actionSheet({
				title: '分享链接',
				cancel: '取消',
				buttons: shareBts
			}, function(e) {
				(e.index > 0) && shareAction(shareBts[e.index - 1], true);
			}) : mui.alert('当前环境无法支持分享链接操作!');
		}
		//判断 点击微信朋友圈还是微信好友  shareBts[e.index - 1]------sb.s
		function shareAction(sb, bh) {
			//			alert(JSON.stringify(sb.s) + "---" + JSON.stringify(sb))
			if(!sb || !sb.s) {
				console.log("无效的分享服务！");
				return;
			}
			var msg = {
				content: '我们一起飞吧！',
				extra: {
					scene: sb.x
				}
			};
			if(bh) {
				var ur = mbank.getApiURL() + 'APP/views/main/' + mbank.getShareUrl() + "##" + mbank.getBankId();
				msg.href = ur;
				msg.title = "开发银行";
				msg.content = "一起体验吧！"; //分享下载链接内容
				msg.thumbs = ["_www/images/icon/icon_" + "XIUWEN_BANK" + ".png"];
				msg.pictures = ["_www/images/icon/icon_" + "XIUWEN_BANK" + ".png"];
			} else {
				if(pic && pic.realUrl) {
					msg.pictures = [pic.realUrl];
				}
			}
			// 发送分享
			if(sb.s.authenticated) {
				shareMessage(msg, sb.s);
			} else {
				sb.s.authorize(function() {
					shareMessage(msg, sb.s);
				}, function(e) {
					mui.alert("认证授权失败：" + e.code + " - " + e.message);
				});
			}
		}

		function shareMessage(msg, s) {
			s.send(msg, function() {
				mui.alert("分享到\"" + s.description + "\"成功！ ");
			}, function(e) {
				//mui.alert("分享到\"" + s.description + "\"失败" + JSON.stringify(e));
			});
		}
	});
});